# """ 公司操作相关接口
# @Project: Rebar
# @File: routers.py
# @Author: hzc
# @Date: 2023/3/27 21:21
# """
from fastapi import APIRouter, Header, Query
from model.db.mapper import get_company
from model.db.mapper.company_mapper import get_company_list, add_company, update_company_info
from model.params import CompanyInfoParam
from model.params.company_params import UpdateComParam
# # from model.params import CompanyInfoParam
# # from utils import success_res, SuccessCode, obj_to_dict, objs_to_dict
from util import success_res, SuccessCode, obj_to_dict, objs_to_dict

company_router = APIRouter(prefix="/companies", tags=['公司管理'])


#
#
# @company_router.post('', name="添加公司")
# async def _add_company(company_info: CompanyInfoParam, token=Header("token")):
#     company = add_company(company_info)
#     return success_res(obj_to_dict(company), SuccessCode.POST)
#
#
@company_router.get('/{company_name}', name="获取指定公司信息")
async def _get_company(company_name: str):
    company = get_company(company_name)
    return success_res(obj_to_dict(company), SuccessCode.GET)


@company_router.post('/list', name="获取公司列表")
async def company_list():
    companys = get_company_list()
    return success_res(objs_to_dict(companys), SuccessCode.GET)


@company_router.post('/update', name="更新公司")
async def company_list(update: UpdateComParam):
    add = update_company_info(update.add, update.delete, update.update)
    return success_res({'add': objs_to_dict(add)}, SuccessCode.GET)

#
# @company_router.get('', name="获取所有公司信息")
# async def _get_companies(
#     page_num: int = Query(default=1, ge=1, title="页码"),
#     page_size: int = Query(default=10, ge=5, le=20, title="每页数据量"),
#     token=Header("token")
# ):
#     companies = get_companies(page_num, page_size)
#     return success_res({
#         'companies': objs_to_dict(companies),
#         'length': len(companies)
#     }, SuccessCode.GET)

# @company_router.get('', name="获取公司信息")
# async def _get_companies(
#     page_num: int = Query(default=1, ge=1, title="页码"),
#     page_size: int = Query(default=10, ge=5, le=20, title="每页数据量"),
#     token=Header("token")
# ):
#     companies = get_companies(page_num, page_size)
#     return success_res({
#         'companies': objs_to_dict(companies),
#         'length': len(companies)
#     }, SuccessCode.GET)
